package com.pug.service.hotel.comment;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pug.entity.HotelComment;
import com.pug.entity.KssUser;
import com.pug.mapper.hotel.HotelCommentMapper;
import com.pug.redis.PugRedisOperator;
import com.pug.threadlocal.UserThrealLocal;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022/3/19$ 16:58$
 */
@Service
@Slf4j
public class HotelCommentRedisServiceImpl extends ServiceImpl<HotelCommentMapper, HotelComment> implements IHotelCommentService {


    @Autowired
    private PugRedisOperator redisOperator;
    @Autowired
    private IHotelCommentUserZanServiceImpl hotelommentUserZanService;


    /**
     * 评论赞+1
     * @param commentId
     * @return
     */
    @Override
    @Transactional
    public int updateCommentPlusZannum(@Param("commentId")Long commentId){
        KssUser kssUser = UserThrealLocal.get();
        //1: 评论表zannum + 1
        redisOperator.incrementHash("redis:user:comment:like",commentId+"",1L);
        redisOperator.setHashValue("redis:comment:like:user", kssUser.getId() + ":" + commentId, "1");
        return 1;
    }

    /**
     * 评论赞 - 1
     * @param commentId
     * @return
     */
    @Override
    @Transactional
    public int updateCommentMiusZannum(@Param("commentId")Long commentId){
        KssUser kssUser = UserThrealLocal.get();
        //1: 评论表zannum + 1
        redisOperator.decrementHash("redis:user:comment:like",commentId+"",1L);
        redisOperator.hdel("redis:comment:like:user", kssUser.getId() + ":" + commentId);
        return 1;
    }
}
